package com.example.homework_5_2;

import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.room.Room;

import java.util.List;

public class First_Page extends AppCompatActivity {

    TextView account_text_view, password_text_view, real_name_text_view, birthday_text_view, id_card_text_view;

    String account, password;
    RoodDataBase roodDataBase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_page);

        roodDataBase = Room.databaseBuilder(this, RoodDataBase.class, "dataDB").allowMainThreadQueries().build();
        account = getIntent().getStringExtra("account");
        password = getIntent().getStringExtra("password");

        account_text_view = findViewById(R.id.account_text_view);
        password_text_view = findViewById(R.id.password_text_view);
        real_name_text_view = findViewById(R.id.real_name_text_view);
        birthday_text_view = findViewById(R.id.birthday_text_view);
        id_card_text_view = findViewById(R.id.id_card_text_view);

        check_has_this_account(account, password);
    }

    public void check_has_this_account(String account, String password) {
        try {
            List<Data> data_list = roodDataBase.dataDao().get_data();
            if (!data_list.isEmpty()) {
                for (int i = 0; i < data_list.size(); i++) {
                    Data data = data_list.get(i);
                    if (data.getAccount_name().equals(account) && data.getAccount_password().equals(password)) {
                        account_text_view.setText(account);
                        password_text_view.setText(password);
                        real_name_text_view.setText(data.getReal_name());
                        birthday_text_view.setText(data.getBirthday());
                        id_card_text_view.setText(data.getId_card());
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}